package com.powernobug.servlet;

import com.powernobug.bean.vo.BaseRespVo;
import com.powernobug.service.ConfigService;
import com.powernobug.service.impl.ConfigServiceImpl;
import com.powernobug.util.JsonUtil;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Map;
import com.powernobug.service.AdminConfigService;
import com.powernobug.service.impl.AdminConfigServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/config/*")
public class AdminConfigServlet extends CommonServlet{

    private static ConfigService configService = new ConfigServiceImpl();
    private static AdminConfigService adminConfigService=new AdminConfigServiceImpl();


    public BaseRespVo mall(HttpServletRequest request) throws IOException{
        String method = request.getMethod();
        if ("GET".equals(method)) {
            return mallQuery(request);
        } else if ("POST".equals(method)) {
            return mallUpdate(request);
        }
        return null;
    }

    public BaseRespVo mallQuery(HttpServletRequest req) throws IOException {
        Map<String,String> data = configService.mallQuery();
        BaseRespVo baseRespVo = BaseRespVo.okList(data);
        return baseRespVo;
    }
    private BaseRespVo mallUpdate(HttpServletRequest req) throws IOException {
        Map<String, String> parameterMap = JsonUtil.readRequestLineToMap(req);
        configService.update(parameterMap);
        return BaseRespVo.okList(null);
    }
    public BaseRespVo express(HttpServletRequest request) throws IOException {
       return adminConfigService.express();
    }
    public BaseRespVo order(HttpServletRequest request) throws IOException {
       return adminConfigService.order();
    }
    public BaseRespVo wx(HttpServletRequest request) throws IOException {
       return adminConfigService.wx();
    }

}
